import webconfig from "../webconfig";
async function ajax(url, options = {}) {
    if (url.indexOf("http") == -1) {
        url = webconfig.gatewayURL.replace('/chunks', '') + url;
    }
    if (!options.method) options.method = "get";
    try {
        let response = await fetch(url, options);
        let msg = 'ok', data = null;
        if (response.ok) {
            data = await response.json();
        } else {
            // data = await response.json();   
            msg =await response.text();
        }
        return { msg, data };
    } catch (e) {
        console.log(e);
        return { msg: 'API or network error' };
    }
}
export default ajax;